
Namespace CommonDialog

    Public Class FolderBrowserDialog

#Region " Declarations "

        Private _bolShowNewFolderButton As Boolean = True
        Private _strDescription As String = String.Empty
        Private _strSelectedPath As String = String.Empty

#End Region

#Region " Properties "

        ''' <summary>
        ''' Gets or sets the descriptive text displayed above the tree view control in the dialog box. 
        ''' </summary>
        Public Property Description() As String
            Get
                Return _strDescription
            End Get
            Set(ByVal Value As String)
                _strDescription = Value
            End Set
        End Property

        ''' <summary>
        ''' Gets or sets the path selected by the user. 
        ''' </summary>
        Public ReadOnly Property SelectedPath() As String
            Get
                Return _strSelectedPath
            End Get
        End Property

        ''' <summary>
        ''' Gets or sets a value indicating whether the New Folder button appears in the folder browser dialog box. 
        ''' </summary>
        Public Property ShowNewFolderButton() As Boolean
            Get
                Return _bolShowNewFolderButton
            End Get
            Set(ByVal Value As Boolean)
                _bolShowNewFolderButton = Value
            End Set
        End Property

#End Region

#Region " Constructors "

        Public Sub New()
        End Sub

#End Region

#Region " Methods "

        ''' <summary>
        ''' Displays the folder browser dialog for the current operating system.  Returns true if the user selected a folder.  Read the SelectedPath property for the selected path.
        ''' </summary>
        Public Function ShowDialog() As Boolean

            Dim objFolderBrowserDialog As New VistaDialogs.VistaFolderBrowserDialog
            Using objFolderBrowserDialog
                objFolderBrowserDialog.Description = Me.Description
                objFolderBrowserDialog.ShowNewFolderButton = Me.ShowNewFolderButton
                objFolderBrowserDialog.UseDescriptionForTitle = False

                Dim objResult As System.Windows.Forms.DialogResult = objFolderBrowserDialog.ShowDialog

                If objResult = Forms.DialogResult.OK Then
                    _strSelectedPath = objFolderBrowserDialog.SelectedPath
                    objFolderBrowserDialog.Dispose()
                    Return True

                Else
                    objFolderBrowserDialog.Dispose()
                    Return False
                End If

            End Using
        End Function

#End Region

    End Class

End Namespace
